//
//  MNDCelebrationViewController.m
//  minidai
//
//  Created by 容贤郁 on 2017/12/14.
//  Copyright © 2017年 迷你金服. All rights reserved.
//

#import "MNDCelebrationViewController.h"

@interface MNDCelebrationViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *celebrationGift;
@property (weak, nonatomic) IBOutlet UIImageView *celebrationWord;
@property (weak, nonatomic) IBOutlet UIButton *celebrationButton;


@end

@implementation MNDCelebrationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImage *giftImage = [UIImage imageNamed:@"celebration_gift"];
    [self.celebrationGift setFrame:CGRectMake((kScreenWidth - giftImage.size.width) / 2, kScreenHeight - giftImage.size.height, giftImage.size.width, giftImage.size.height)];
    
    UIImage *wordImage = [UIImage imageNamed:@"celebration_word"];
    [self.celebrationWord setFrame:CGRectMake((kScreenWidth - wordImage.size.width) / 2, kScreenHeight - wordImage.size.height, wordImage.size.width, wordImage.size.height)];
    
    UIImage *btnImage = [UIImage imageNamed:@"celebration_btn"];
    [self.celebrationButton setFrame:CGRectMake((kScreenWidth - btnImage.size.width) / 2, kScreenHeight - btnImage.size.height, btnImage.size.width, btnImage.size.height)];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    CGRect giftFrame = self.celebrationGift.frame;
    CGRect wordFrame = self.celebrationWord.frame;
    CGRect btnFrame  = self.celebrationButton.frame;
    
    [UIView animateWithDuration:0.5 animations:^{
        self.celebrationGift.alpha = 1.0;
        
        [self.celebrationGift setFrame:CGRectMake(giftFrame.origin.x, (kScreenHeight - giftFrame.size.height) / 2, giftFrame.size.width, giftFrame.size.height)];
        
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.5 animations:^{
            self.celebrationWord.alpha = 1.0;
            
            [self.celebrationWord setFrame:CGRectMake(wordFrame.origin.x, self.celebrationGift.frame.origin.y + self.celebrationGift.frame.size.height + 33, wordFrame.size.width, wordFrame.size.height)];
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:0.5 animations:^{
                self.celebrationButton.alpha = 1.0;
                
                [self.celebrationButton setFrame:CGRectMake(btnFrame.origin.x, self.celebrationWord.frame.origin.y + self.celebrationWord.frame.size.height + 12, btnFrame.size.width, btnFrame.size.height)];
            }];
        }];
    }];
}

- (IBAction)closeCelebrationView:(UIButton *)sender {
    
    [self.view removeFromSuperview];
    
    [self removeFromParentViewController];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
